﻿var g = jQuery.noConflict();
g(function() {
    g("#Previous").button();
    g("#SaveCondition").button();
    g("#UploadFile").button();
    g(window.parent.document).find("#contentTitle").text("条件设置");
    g.fx.speeds._default = 1000;
	g( "#dialog" ).dialog({
		autoOpen: false,
		closeOnEscape: false,
		bgiframe: true,
		modal: true,
		draggable: false,
        resizable: false,
		open: function(event,ui){ g(".ui-dialog-titlebar-close").hide(); }
	});
	g("#UploadFile").click(function(){
	    var fso=new ActiveXObject("Scripting.FileSystemObject");
	    var opath=fso.GetFile(g("#ServiceIdImport").val());
	    if(opath.size > (300*1024))
	    {
	        alert("上传文件超过300K请分批查询！");
	        return false;
	    }
	    else
	    {
	        g("#tip").text("正在上传文件...");
	        g( "#dialog" ).dialog( "open" );
	        return true;
	    }
	});
	g( "#SaveCondition" ).click(function() {			    
		var mime = g("#ServiceIdImport").val().substr(g("#ServiceIdImport").val().lastIndexOf('.')+1);
		if(mime.length > 0 && mime.toLowerCase() != "txt")
		{
		    alert("只能上传TXT格式文件!");
		    return false;
		}
		else
		{
		    if(g("#UploadFile").val() == "上传" && g("#ServiceIdImport").val().length > 0)
            {
                if(!confirm("您选择的文件尚未上传，是否继续提交？"))
                {
                    g("#UploadFile").focus();
                    return false;
                }
            }	
		    g( "#dialog" ).dialog( "open" );
		    return true;
		}		
	});
	g( "#txtDiv" ).dialog({
		autoOpen: false,
		bgiframe: true,
		width:800,
		height:480
	});
	g("#openView").click(function(){
	    g('#txtDiv').dialog( 'open' );
	    return false;
	});
	g("#FBList").change(function(){
	    g("#HidOrga").val("");
	    if(g("#FBList").val() == "")
	    {
	        g("#OrgaList").hide();
	        g("#OrgaList").empty();
	        return;
	    }
        var mData = Operate_Conditions.GetBscByFB(g("#FBList").val()).value;        
        if(mData == null)
        {
            alert("数据访问异常，请重试！若该问题重复出现，请联系系统管理员。");
        }
        else if(mData.length == 0)
        {
            g("#OrgaList").hide();
            g("#OrgaList").empty();
        }
        else if(mData.length > 0)
        {            
            g("#OrgaList").empty();
            for(var i=0;i<mData.length;i++)
            {
                g("#OrgaList").append(g("<option value='" + mData[i].FenBu + "'>" + mData[i].FenBu + "</option>"));
            }       
            g("#OrgaList").show();                
        }
	});
	g("#OrgaList").change(function(){
        g("#HidOrga").val(g("#OrgaList").val());
    });
	g("#ViewFrame").attr("src","TxtExample.html");
});